package org.aepage.logmailer.example;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import org.aepage.logmailer.LogMailer;

/**
 * Simple Example
 * Created with IntelliJ IDEA.
 * User: andrew
 * Date: 2/23/14
 * Time: 5:42 PM
 * To change this template use File | Settings | File Templates.
 */
public class LogMailerExample extends Activity {

  public static final int LOGMAILER_REQUEST_CODE = 101;
  public static final String TAG = "LOGMAILER" ;
  private TextView resultText ;
  private EditText emailAddressText ;
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.examplemain);


    emailAddressText = (EditText)findViewById(R.id.emailAddress) ;

    Button b = (Button)findViewById(R.id.button) ;
    b.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View view) {
        doGo() ;
      }
    });
  }

  @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    switch( requestCode ) { // more code than necessary but lays out the boilerplate for other cases
      case LOGMAILER_REQUEST_CODE:
        processLogMailerResult(resultCode, data);
        break ;
    }

  }

  private void processLogMailerResult(int resultCode, Intent data) {
    if( data == null )
      return ;
    String log = data.getStringExtra(LogMailer.LOG_DATA_EXTRA) ;

  }

  public static void i(String fmt, Object ... args) {
    Log.i(TAG, String.format(fmt, args)) ;
  }

  /**
   * respond to buttom press
   */
  private void doGo() {
    Intent i = new Intent(this, LogMailer.class) ;

    Log.i("LOGMAILER", "Launching LogMailer activity") ;

    i.putExtra(LogMailer.EMAIL_ADDRESS_EXTRA, emailAddressText.getText().toString()) ;

    startActivityForResult(i, LOGMAILER_REQUEST_CODE);

  }
}
